home *** CD-ROM | disk | FTP | other *** search
- 'Drag Example
- 'By Dave Kelly
- '©MacTutor, 1988
-
- WINDOW OFF
- COORDINATE WINDOW
- DEF MOUSE=-1
- DIM Rect%(3),pt%(1),pin%(3),bnd%(3),dir%,dis&
- pt%(0)=mousey%:pt%(1)=mousex%
- 'Create DragGrayRect function
- LONG FN DragGrayRect&(RL%,RT%,RR%,RB%,mousey,mousex,PL%,PT%,PR%,PB%,BL%,BT%,BR%,BB%,dir%)
- ' Rect% = the rectangle to be moved
- ' pt% = the point where the mouse was pushed.
- ' pin% = the rectangular limits in which the outline can be dragged.
- ' bnd% = the rectangular boundary for a drag.
- ' dir% = the direction to which the drag is constrained
- ' 0 = no constraint, 1 = horizontal, 2 = vertical
- ' dis& = A point array that returns the drag displacement.
- CALL SETRECT(Rect%(0),RL,RT,RR,RB)
- CALL SETRECT(pin%(0),PL,PT,PR,PB)
- CALL SETRECT(bnd%(0),BL,BT,BR,BB)
- RgnHand&=FN NEWRGN
- CALL OPENRGN
- CALL FRAMERECT(Rect%(0))
- CALL CLOSERGN(RgnHand&)
- pt%(0)=mousey%:pt%(1)=mousex%:Proc&=0:dis&=0
- dis&=FN DRAGGRAYRGN(RgnHand&,pt%(0),pin%(0),bnd%(0),dir%,Proc&)
- CALL DISPOSERGN(RgnHand&)
- END FN=dis&
- 'Find out monitor size
- CALL GETWMGRPORT(WMgrPort&)
- PortTop=PEEK WORD(WMgrPort&+8)
- PortLeft=PEEK WORD(WMgrPort&+10)
- PortBottom=PEEK WORD(WMgrPort&+12)
- PortRight=PEEK WORD(WMgrPort&+14)
- WINDOW#1,"DragExample",(PortLeft+4,PortTop+42)-(PortRight-6,PortBottom-6),5
- MENU 1,0,1,"File"
- MENU 1,1,1,"Quit"
- top=100:left=100
- GOSUB "DrawBox"
- MOUSE ON:MENU ON:DIALOG ON
- ON MOUSE GOSUB "MouseEvent"
- ON MENU GOSUB "MenuEvent"
- ON DIALOG GOSUB "DialogEvent"
- "Loop"
- DO
- UNTIL Done
- MOUSE OFF:MENU OFF:DIALOG OFF
-
- "DialogEvent"
- D=DIALOG(0)
- IF D=4 THEN END
- RETURN
-
- "MenuEvent"
- Menunumber=MENU(0)
- Menuitem=MENU(1)
- IF Menunumber=1 AND Menuitem=1 THEN END
- MENU
- RETURN
-
- "MouseEvent"
- X=MOUSE(0)
- mousey=MOUSE(2):mousex=MOUSE(1)
- IF mousey=0 AND mousex=0 THEN END
- dir%=0
- dis&= FN DragGrayRect&(left,top,left+100,top+100,mousey,mousex,PortLeft,PortTop,PortRight,PortBottom,PortLeft,PortTop,PortRight,PortBottom,dir%)
- dy=FN HIWORD(dis&)
- dx=FN LOWORD(dis&)
- LONG IF dx<>0 AND dy<>0
- CALL ERASERECT(Rect%(0))
- top=top+dy:left=left+dx
- GOSUB "DrawBox"
- END IF
- RETURN
-
- "DrawBox"
- CALL SETRECT(Rect%(0),left,top,left+100,top+100)
- CALL FORECOLOR(205): ' color = red
- CALL PAINTRECT(Rect%(0))
- RETURN
-